import sys, os
sys.path.append(os.pardir)  # 为了导入父目录而进行的设定
import numpy as np
import matplotlib.pyplot as plt
from D_net import dNet
from common.trainer import Trainer
from common.functions import *
from data_deal import d_loaddatas


network = dNet()


x_train, t_train = d_loaddatas()
x_test, t_test = x_train, t_train
x_train=x_train.transpose(0,3,1,2)
x_test=x_test.transpose(0,3,1,2)

# test_img=x_train[25,:,:,:]
#plt.imshow(test_img)
# test_img=np.expand_dims(test_img, axis=0)
# p=network.predict(test_img)

# l=network.loss(test_img,1)
# t=7
# plt.imshow(np.hstack([x_train[t,:,:,0:3],x_train[t,:,:,3:6]]))


#network.load_params("deep_convnet_params.pkl")
#network.accuracy(x_test,t_test)
#network.predict(np.expand_dims(x_train[1000],axis=0))

trainer = Trainer(network, x_train, t_train, x_test, t_test,
                  epochs=100, mini_batch_size=100,
                  optimizer='adam', lr=0.0008,
                  evaluate_sample_num_per_epoch=100)


trainer.train()

# 保存参数
network.save_params("deep_convnet_params.pkl")
print("Saved Network Parameters!")
